import random


def change(s2):
    if s2.__len__() == 1:
        s2 = "00" + s2
    if s2.__len__() == 2:
        s2 = "0" + s2
    if s2.__len__() == 3:
        s2 = s2
    return s2


"""for i in range(200):
    s1 = str(i)
    s = s + change(s1) + ".txt"
    s = "C://Users//cwh//Desktop//classes//" + s
    print(s)
    f = open(s, "r+")
    s = "c"
"""


def supplement(ts):
    credit = str(random.randint(1, 7))
    first_line = ts + " " + "30%" + " " + "70%" + " " + credit
    return first_line


def supplement1(sid):
    us = str(random.randint(50, 100))
    es = str(random.randint(40, 100))
    ss = sid + " " + us + " " + es
    return ss


def make_class():
    tf = open("C://Users//cwh//Desktop//classes//teacherInfo.txt", "r+")
    while True:
        ts = tf.readline()
        if not ts:
            break
        if ts[0] == "#":
            continue
        t_id = ts[:4]
        t_count = len(ts)
        b_num = 0
        k = 0
        for k in range(t_count):
            if ts[k] == " ":
                b_num = b_num + 1
            if b_num == 4:
                break
        if ts[k+1] == "#":
            continue
        for l in range(k + 1, t_count - 1, 3):
            ts1 = ts[l:l + 3]
            first_line = supplement(ts1)
            ts1 = "c" + ts1 + ".txt"
            file_name = "C://Users//cwh//Desktop//classes//" + ts1
            f = open(file_name, "r+")
            data = f.read()
            if len(data) == 0:
                f.write(first_line)
                f.write("\n")
                f.write(t_id)
                f.close()
            else:
                f.close()
                f = open(file_name, 'a')
                f.write(t_id)
                f.close()
                continue


# make_class()
def enter_student():
    sf = open("C://Users//cwh//Desktop//classes//studentInfo.txt", "r+")
    while True:
        ss = sf.readline()
        if not ss:
            break
        if ss[0] == "#":
            continue
        s_id = ss[:10]
        s_count = len(ss)
        b_num = 0
        j = 0
        for j in range(s_count):
            if ss[j] == " ":
                b_num = b_num + 1
            if b_num == 6:
                break
        for c in range(j+1, s_count-1, 3):
            sc = ss[c:c+3]
            filename = "C://Users//cwh//Desktop//classes//c" + sc + ".txt"
            f = open(filename, 'a')
            line = supplement1(s_id)
            f.write("\n")
            f.write(line)
            f.close()


enter_student()
